package mil.af.amc.adpetracker.dao.hibernate;

import mil.af.amc.adpetracker.model.Ros;
import mil.af.amc.adpetracker.model.AdpeAccount;
import mil.af.amc.adpetracker.dao.RosDao;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import java.util.List;

/**
 * Hibernate implementation of ROS DAO
 *
 * @author TSgt Jason Ferguson
 */

public class HibernateRosDao extends HibernateGenericDao<Ros> implements RosDao {

    public HibernateRosDao() {
        super(Ros.class);
    }

    @SuppressWarnings({"unchecked"})
    public Ros getByTrackingNumber(String trackingNumber) {

        DetachedCriteria crit = DetachedCriteria.forClass(Ros.class);
        crit.add(Restrictions.eq("trackingNumber", trackingNumber));

        List<Ros> results = getHibernateTemplate().findByCriteria(crit);

        if (results.size() == 0) {
            return null;
        } else {
            return results.get(0);
        }
    }

    @SuppressWarnings({"unchecked"})
    public List<Ros> getByAdpeAccount(AdpeAccount acct) {

        DetachedCriteria crit = DetachedCriteria.forClass(Ros.class);
        crit.add(Restrictions.eq("adpeAccount", acct));

        return getHibernateTemplate().findByCriteria(crit);
    }
}
